<?
class page{
   static function add($pas_title,$pas_cat_id,$pas_image,$pas_summary='',$pas_description='',$pas_status=1){
      if($pas_title != '' ){
         $sql= " INSERT INTO pages_static(
                        pas_title,
                        pas_cat_id,
                        pas_images,
                        pas_date,
                        pas_summary,
                        pas_description,
                        pas_status
                        )
               VALUES('" . $pas_title . "'," . $pas_cat_id . ",'" . $pas_image . "'," . time() . ",'" . $pas_summary . "','" . $pas_description . "'," . $pas_status . ")";
         $db_exe = new db_execute($sql);
         unset($db_exe);                        
      }
   }
   static function view($pas_id){
      $result = array();
      $db_sel = new db_query("SELECT * 
                              FROM pages_static 
                              WHERE pas_id=" . $pas_id);
      $result = $db_sel->resultArray();
      unset($db_sel);
      return $result;
   }
   static function delete($pas_id){
      $db_exe = new db_execute("DELETE 
                                FROM pages_static 
                                WHERE pas_id=" . $pas_id);
      unset($db_exe);
   }
   static function update($pas_id,$array=array()){
      if(isset($pas_id) && count($array) > 0){
            $set_sql = self::sql_update($pas_id,$array);
            echo $set_sql;
            //$db_exe = new db_execute($set_sql);
            //unset($db_exe);
      }
   }
   static function search($keyword){
      $result = array();
      if($keyword != ''){
         if(str_word_count($keyword) >= 4){
            $query = "SELECT *,MATCH(pas_title) AGAINST('" . $keyword . "' IN BOOLEAN MODE) as point   
                      FROM pages_static
                      WHERE MATCH(pas_title) AGAINST('" . $keyword . "' IN BOOLEAN MODE)
                      HAVING point >= 1
                      ORDER BY point DESC";
         }else{
            $query = "SELECT * 
                      FROM pages_static WHERE pas_title LIKE'%" . $keyword . "%'";
         }
         $db_sel = new db_query($query);
         $result = $db_sel->resultArray();
         unset($db_sel); 
      }
      return $result;
   }
   protected function sql_update($id,$array=array()){
      $query = "UPDATE pages_static";
      $set_query = " ";
      foreach($array as $key=>$value){
         if($key == 'pages_date' || $key == 'pages_status' || $key == 'pages_cat_id')
            $set_query .= $key . "=" . $value . ",";
         else
            $set_query .= $key . "='" . $value . "',";    
      }
      $query .= ' SET ' . $set_query;
      return substr($query,0,-1) . " WHERE pas_id=" . $id;
   }
 }
?>
